# -*- coding: utf-8 -*-
"""
报表 Provider 模块聚合入口。
"""
from typing import Any, Dict, Type

from .base import BaseProvider, SafeDict  # noqa: F401
from .starrocks.cps_quality import CPSDataQualityProvider  # noqa: F401
from .starrocks.cps_base_statistics import CPSBaseStatisticsProvider  # noqa: F401

_STATIC_PROVIDER_MAP: Dict[str, Type[BaseProvider]] = {
    "cps_data_quality_monitor": CPSDataQualityProvider,
    "cps_base_statistics_report": CPSBaseStatisticsProvider,
}


def get_provider(template_code: str, params: Dict[str, Any]) -> BaseProvider:
    """
    根据模板编码返回 Provider 实例。
    """
    from app.blueprints.reports.registry.registry import TemplateRegistry

    descriptor = TemplateRegistry.get(template_code)
    provider_class: Type[BaseProvider] | None = None
    if descriptor:
        provider_class = descriptor.provider_class

    if provider_class is None:
        provider_class = _STATIC_PROVIDER_MAP.get(template_code)

    if provider_class is None:
        raise ValueError(f"Unknown template code: {template_code}")

    return provider_class(params, template_code)


__all__ = [
    "BaseProvider",
    "SafeDict",
    "DataQualityMonitorProvider",
    "CPSDataQualityProvider",
    "get_provider",
]


